package com.gxa.controller;

import com.gxa.common.base.RespResult;
import com.gxa.domain.dto.NewGoodsDto;
import com.gxa.domain.entity.NewGoods;
import com.gxa.service.NewGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 吴邓江
 * 大帅哥
 */
@RestController
@Slf4j
@RequestMapping("/logistics_new_goods")
@Api(tags = "新商品管理")
public class NewGoodsController {
    @Autowired
    private NewGoodsService newGoodsService;

    /**
     * 获取新商品列表
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取新商品列表", notes = "获取新商品列表")
    public RespResult list() {
        log.info("获取新商品列表");
        List<NewGoods> list = newGoodsService.list();
        return RespResult.success(list);
    }


    @PostMapping("/save")

    @ApiOperation(value = "新增新商品", notes = "新增新商品")
    public RespResult save(@RequestBody NewGoods newGoods) {
        log.info("新增新商品:{}", newGoods);

        newGoodsService.save(newGoods);
        return RespResult.success();
    }

    /**
     * 根据id获取新商品
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取新商品", notes = "根据id获取新商品")
    public RespResult get(@PathVariable("id") Integer id) {
        log.info("根据id获取新商品:{}", id);
        NewGoods newGoods = newGoodsService.getById(id);
        return RespResult.success(newGoods);
    }

    /**
     * 修改新品
     * @param newGoods
     * @return
     */

    @PostMapping("/update")
    @ApiOperation(value = "修改新商品", notes = "修改新商品")
    public RespResult update(@RequestBody NewGoods newGoods) {
        log.info("修改新商品:{}", newGoods);
        newGoodsService.updateById(newGoods);
        return RespResult.success();
    }

    /**
     * 根据id删除新品
     */
    @PostMapping("/{id}")
    @ApiOperation(value = "删除新商品", notes = "删除新商品")
    public RespResult delete(@PathVariable("id") Integer id) {
        log.info("删除新商品:{}", id);
        newGoodsService.removeById(id);
        return RespResult.success();
    }

    @GetMapping("/page")

    @ApiOperation(value = "分页查询新商品", notes = "分页查询新商品")
    public RespResult page(NewGoodsDto newGoodsDto){
        log.info("分页查询新商品:{}", newGoodsDto);
        return newGoodsService.pagequery(newGoodsDto);
    }
}
